#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#define lld long long // long long 的
#define ENDL '\n'     // 将 endl 替换为 \n 取消缓冲区

using std::cin;
using std::cout;

using std::vector;
void solve() {

  int n;
  cin >> n;
  vector<lld> s(n);
  vector<lld> t(n);
  lld mx_ = -1;
  for (int i = 0; i < n; ++i)
    cin >> s[i];
  int M = *std::max_element(s.begin(), s.end());

  for (int i = 0; i < n; ++i)
    t[i] = M - s[i];
  lld sum = t[0];
  /*
  int peak_sum = 0;
    int valley_sum = 0;
    for (int i = 1; i < n - 1; ++i) {
      if (t[i] >= t[i - 1] && t[i] > t[i + 1]) {
        peak_sum += t[i];
      } else if (t[i] <= t[i - 1] && t[i] < t[i + 1]) {
        valley_sum += t[i];
      }
    }
  */
  for (int i = 0; i < n - 1; ++i)
    if (t[i + 1] > t[i])
      sum += t[i + 1] - t[i];

  cout << sum << ENDL;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}